/**
 * Created by zilong on 8/3/15.
 */
var path = require('path')

var express = require('express')
var app = express()

var exphbs = require('express-handlebars')
var expHelper = require('./tpl_helper');
var config = require('./config')

app.set('views', path.join(__dirname, 'views'));
app.engine('html', exphbs({
    defaultLayout: 'masterPage',//自动到layouts文件夹下去找
    extname: '.html',
    helpers:expHelper
}));

app.set('view engine', 'html');


app.locals.Views = config.Views

var mainRouter = require('./router/main')
app.use('/', mainRouter);


app.use(express.static(path.join(__dirname, 'public')));


if(config.Env=='prod'){
    console.log('prod')
    app.enable('view cache');
}


var server = app.listen(3000,function(){
    var host = server.address().address;
    var port = server.address().port;

    console.log('app listening at http://%s:%s', host, port);
})